package com.woniu.car.controller;
import com.woniu.car.annotation.TelAndCodeCheck;
import com.woniu.car.common.ResponseEntity;
import com.woniu.car.dto.ShopAccountDto;
import com.woniu.car.param.ShopLoginByCodeParam;
import com.woniu.car.service.TShopAccountService;
import com.woniu.car.util.Code;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WWX
 * @since 2021-06-19
 */
@Api(tags = "商家账号控制器")
@RestController
@RequestMapping("/tShopAccount")
public class TShopAccountController {
    @Resource
    private TShopAccountService tShopAccountService;
    /**
     *@Author 王维鑫
     *@Description 商铺注册
     *@Param
     *@return
     **/
//    @TelAndPwdCheck
//    @ApiOperation("商家账号注册接口")
//    @PostMapping("shopRegister")
//    public ResponseEntity shopRegister(@RequestBody ShopRegisterParam param) throws Exception {
//        ShopRegisterDto shopAccountDto = tShopAccountService.registerShopAccount(param);
//        return  ResponseEntity.builder(ShopRegisterDto.class).setObject(shopAccountDto).setCode(Code.NORMAL).setMsg("注册成功");
//    }
    /**
     *@Author 王维鑫
     *@Description 商铺短信登录
     *@Param
     *@return
     **/
    @TelAndCodeCheck
    @ApiOperation("商家账号短信登录接口")
    @GetMapping("loginByCode")
    public ResponseEntity shopLoginByCode(ShopLoginByCodeParam param) throws Exception {
        ShopAccountDto shopAccountDto = tShopAccountService.loginShopByCode(param);
        Integer shopId = shopAccountDto.getShopAccountId();
        String token = JWTUtil.generatorShopAccountJWT(shopId.toString());
        shopAccountDto.setToken(token);
        return ResponseEntity.builder(ShopAccountDto.class).setObject(shopAccountDto).setCode(Code.NORMAL).setMsg("登录成功");
    }

}

